package com.enation.app.shop.front.api.commentagain.service;

import com.enation.app.shop.front.api.commentagain.entity.CommentAgain;
import com.enation.framework.database.IDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service("CommentAgainService")
public class CommentAgainManager implements ICommentAgainManager {
    @Autowired
    private IDaoSupport daoSupport;
    @Override
    public int create(CommentAgain commentAgain) {
        this.daoSupport.insert("rbt_comment_again",commentAgain);
        //int creditid = this.daoSupport.getLastId("rbt_comment_again");
        return 1;
    }

    @Override
    public int delete(Integer commentagainid) {
        String sql="delete from rbt_comment_again where comment_again_id=?";
        this.daoSupport.execute(sql,commentagainid);
        return 1;
    }

    @Override
    public List<CommentAgain> getAll(Integer commentid) {
        String sql="select * from rbt_comment_again where comment_id=?";
        List<CommentAgain> commentAgains=this.daoSupport.queryForList(sql,CommentAgain.class,commentid);
        return commentAgains;
    }

    @Override
    public List<CommentAgain> getByUseridAndCommentid(Integer userid, Integer commentid) {
        String sql="select * from rbt_comment_again where comment_id=? and user_id=?";
        List<CommentAgain> commentAgains=this.daoSupport.queryForList(sql,CommentAgain.class,userid,commentid);
        return commentAgains;
    }

    @Override
    public int getCount(Integer commentid) {
        String sql="select count(*) from rbt_comment_again where comment_id=?";
        System.out.println(sql);
        int count=this.daoSupport.queryForInt(sql,commentid);
        return count;
    }
}
